#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "aqp/aqp.hpp"
#include <QThread>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    view = new XbelView();
    setCentralWidget(view);
    setWindowTitle(tr("Metodika"));
    resize(600, 400);
}

MainWindow::~MainWindow()
{
    delete ui;
    delete view;
}

//void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
//{
//    QList <QModelIndex> indexs;
//     if(selection->hasSelection())   {
//         indexs = selection->selectedIndexes();
//         QStandardItem *item = xbelmodel->itemFromIndex(indexs[0]);
//         view->mouseDoubleClickEvent(event, item);
//    }
//}

void MainWindow::on_actionOpen_triggered()
{
    view->on_actionOpen_triggered();
}

void MainWindow::on_actionSave_triggered()
{
    view->on_actionSave_triggered();
}

void MainWindow::on_actionExit_triggered()
{
    close();
}

void MainWindow::on_actionInsert_triggered()
{
    view->on_actionInsert_triggered();
}

void MainWindow::on_actionInsertChild_triggered()
{
    QMessageBox::about(0,tr("Предупреждение"),tr("Будет заменена на перемещение строк"));
}

void MainWindow::on_actionDelete_triggered()
{
    view->on_actionDelete_triggered();
}

void MainWindow::on_actionRas_triggered()
{
    view->on_actionRas_triggered();
}

void MainWindow::on_actionAbout_triggered()
{
    QMessageBox::about(this, tr("О программе Metodika"),
                       tr(" Программа <b>Metodika</b> разработана для "
                          "автоматизации вычислений и упрощения составления "
                          "эргономического дерева. \n"
                          "В случае обнаружения ошибок в работе программы пишите на почту "
                          "<a href= \"mailto:iukash@rambler.ru\">iukash@rambler.ru</a>"));
}

void MainWindow::on_actionNew_triggered()
{
    view->on_actionNew_triggered();
}

void MainWindow::closeEvent(QCloseEvent *evnt)
{
    if(on_actionClose_triggered())
    {
        evnt->accept();
    }
    else
    {
        evnt->ignore();
    }
}

bool MainWindow::on_actionClose_triggered()
{
    if(view->on_actionClose_triggered())
    {
        return true;
    }
    else
    {
        return false;
    }

}

void MainWindow::on_actionPrint_triggered()
{
    view->on_actionPrint_triggered();
}

void MainWindow::on_actionSend_triggered()
{
    view->on_actionSend_triggered();
}

void MainWindow::on_actionTest_triggered()
{
    view->on_actionTest_triggered();
}
